import { action } from 'mobx';

import ListBaseStore from './ListBaseStore';
import * as MineApis from '../apis/mine';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

/**
 * 我的帖子Store
 */
export default class MineStore extends ListBaseStore {
	constructor() {
		super();
		this.title = getLabel(81733, '我的帖子');
		this.selectedKey = 'all';
	}

	@action doInit = () => {
		this.doBaseInit();
    this.selectedKey = 'all';
    this.initConditionDatas(); // 初始化高级搜索区域
    this.doTableLoading(); // 初始化列表
	}
	// 加载列表数据
	@action doTableLoading = (params) => {
		this.showLoading(true);

		let resultParams = this.getFormParams();
		let commonParams = {
			searchType: this.selectedKey ? this.selectedKey : 'all',
		};
		resultParams = { ...resultParams, ...commonParams, ...params };

		MineApis.getCoworkMineList(resultParams).then(
			(result) => {
				const sessionkey = result.sessionkey;
				this.sessionkey = sessionkey;
				this.comsWeaTableStore.getDatas(sessionkey, 1);

				this.showLoading(false);
			},
		);
	}

	// 初始化收藏的帖子页面查询条件
	@action initConditionDatas = (params) => {
		MineApis.getCoworkMineShareCondition(params).then(
			(result) => {
				const { conditioninfo, topTab } = result;
				this.topTab = topTab;
				this.conditioninfo = conditioninfo;

				this.initFormFields(conditioninfo); // 一定要先初始化initFormFields表单对象
			},
		);
	}
}
